package com.udata.client.view.impl;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Cookies;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.udata.client.place.DocumentPlace;
import com.udata.client.view.DashboardHeaderView;
import com.udata.client.view.DashboardView;
import com.udata.client.view.DocumentView;
import com.udata.client.view.DocumentView.Presenter;
import com.udata.client.view.impl.UserViewImpl.Style;
import com.udata.shared.CookiesConfig;
import com.udata.shared.conf.TokenConfig;

public class DashboardHeaderViewImpl extends Composite implements DashboardHeaderView {
  private static DashboardHeaderViewImplUiBinder uiBinder = GWT
                                                              .create(DashboardHeaderViewImplUiBinder.class);

  interface DashboardHeaderViewImplUiBinder extends UiBinder<Widget, DashboardHeaderViewImpl> {
  }

  interface Style extends CssResource {

  }

  @UiField
  Style             style;

  @UiField
  Label             userLabel;

  @UiField
  Label             documentLabel;

  private Presenter presenter;

  public DashboardHeaderViewImpl() {
    initWidget(uiBinder.createAndBindUi(this));
    String userName = Cookies.getCookie(CookiesConfig.USERNAME);
    userLabel.setText(userName);
  }

  @Override
  public void setPresenter(Presenter presenter) {
    this.presenter = presenter;
  }

  @UiHandler("userLabel")
  public void clickUserLabel(ClickEvent clickEvent) {
    presenter.goTo(new DocumentPlace(TokenConfig.DOCUMENT));

  }

}
